package main

import (
	"bytes"
	"io/ioutil"
	"log"
	"net/http"

	"gitee.com/mdgsf/HTTPUseProtoBuf"
	"github.com/golang/protobuf/proto"
)

func main() {
	reg := &HTTPUseProtoBuf.Register{}
	reg.Username = proto.String("huangjian")
	reg.Password = proto.String("4321")
	reg.Age = proto.Int32(3)
	reg.Email = proto.String("1342042894@qq.com")

	data, err := proto.Marshal(reg)
	if err != nil {
		log.Fatal("marshaling error:", err)
	}
	body := bytes.NewBuffer(data)

	url := "http://localhost:9090/protoPostRegister"
	contentType := "application/json;charset=utf-8"
	res, err := http.Post(url, contentType, body)
	if err != nil {
		log.Panic("http post failed")
	}

	result, err := ioutil.ReadAll(res.Body)
	res.Body.Close()

	log.Println(result)
	log.Println(string(result))
}
